package qf.service.serviceImpl;

import qf.dao.UserDao;
import qf.pojo.User;
import qf.service.UserService;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.service.serviceImpl
 * @Description:
 * @Date 2022/5/27 13:08
 */
public class UserServiceImpl implements UserService {
    private UserDao userdao;
    public UserServiceImpl(UserDao userdao){
        this.userdao = userdao;
    }

    public User login(String username, String password) {
        User user = userdao.selectUser(username);
        //判断密码是否与数据库一致
        if(user.getPassword().equals(password)){
            return null;
        }
        //判断状态知否为激活 1为激活 2为未激活
        if (user.getState() != 2) {
            return null;
        }
        return user;
    }

    public boolean registered(String username, String password) {
        User user = new User();
        if (username == null ||"".equals(username)) {
            return false;
        }
        if (password == null ||"".equals(password)) {
            return false;
        }
        user.setUsername(username);
        user.setPassword(password);
        user.setState(1);
        int i = userdao.registeredUser(user);
        if (i ==0) {
            return false;
        }
        return true;

    }
}
